package org.jeecg.modules.gongqiang.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.util.oConvertUtils;
import org.jeecg.modules.gongqiang.entity.OrderIndexArm;
import org.jeecg.modules.gongqiang.mapper.OrderIndexArmMapper;
import org.jeecg.modules.gongqiang.service.IOrderIndexArmService;
import org.jeecg.modules.gongqiang.vo.AccountVarietyParams;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Description: order_index_arm
 * @Author: jeecg-boot
 * @Date:   2024-09-12
 * @Version: V1.0
 */
@Service
public class OrderIndexArmServiceImpl extends ServiceImpl<OrderIndexArmMapper, OrderIndexArm> implements IOrderIndexArmService {

    @Override
    public OrderIndexArm searhInfos(String id) {
        LambdaQueryWrapper<OrderIndexArm> queryWrapperOrderIndexArm=new LambdaQueryWrapper<>();
        queryWrapperOrderIndexArm.eq(OrderIndexArm::getAccountVarietyId,id);
        OrderIndexArm orderIndexArm = this.getOne(queryWrapperOrderIndexArm);
        if(oConvertUtils.isEmpty(orderIndexArm))
        {
            return null;
        }
        //othereParamsjson话

        String jsonString = orderIndexArm.getParams();
        JSONArray jsonArray = JSON.parseArray(jsonString);
        List<Map<String,String>> mapList=new ArrayList<>();
        for (int i = 0; i < jsonArray.size(); i++) {
            // 获取每个位置上的JSONObject
            JSONObject jsonObject = jsonArray.getJSONObject(i);

            // 从JSONObject中获取键值对
            String paramName = jsonObject.getString("paramName");
            String paramValue = jsonObject.getString("paramValue");
            Map<String,String> map=new HashMap<>();
            map.put(paramName,paramValue);
            mapList.add(map);
        }

        orderIndexArm.setOtherParam(mapList);

        return orderIndexArm;

    }

}
